// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.IndexManagement
{
	internal sealed class ExplainAnalyzeTokenConverter : JsonConverter<ExplainAnalyzeToken>
	{
		public override ExplainAnalyzeToken Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
		{
			if (reader.TokenType != JsonTokenType.StartObject)
				throw new JsonException("Unexpected JSON detected.");
			string bytes = default;
			long endOffset = default;
			bool? keyword = default;
			long position = default;
			long positionlength = default;
			long startOffset = default;
			long termfrequency = default;
			string token = default;
			string type = default;
			Dictionary<string, object> additionalProperties = null;
			while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
			{
				if (reader.TokenType == JsonTokenType.PropertyName)
				{
					var property = reader.GetString();
					if (property == "bytes")
					{
						bytes = JsonSerializer.Deserialize<string>(ref reader, options);
						continue;
					}

					if (property == "end_offset")
					{
						endOffset = JsonSerializer.Deserialize<long>(ref reader, options);
						continue;
					}

					if (property == "keyword")
					{
						keyword = JsonSerializer.Deserialize<bool?>(ref reader, options);
						continue;
					}

					if (property == "position")
					{
						position = JsonSerializer.Deserialize<long>(ref reader, options);
						continue;
					}

					if (property == "positionLength")
					{
						positionlength = JsonSerializer.Deserialize<long>(ref reader, options);
						continue;
					}

					if (property == "start_offset")
					{
						startOffset = JsonSerializer.Deserialize<long>(ref reader, options);
						continue;
					}

					if (property == "termFrequency")
					{
						termfrequency = JsonSerializer.Deserialize<long>(ref reader, options);
						continue;
					}

					if (property == "token")
					{
						token = JsonSerializer.Deserialize<string>(ref reader, options);
						continue;
					}

					if (property == "type")
					{
						type = JsonSerializer.Deserialize<string>(ref reader, options);
						continue;
					}

					additionalProperties ??= new Dictionary<string, object>();
					var value = JsonSerializer.Deserialize<object>(ref reader, options);
					additionalProperties.Add(property, value);
				}
			}

			return new ExplainAnalyzeToken { Bytes = bytes, EndOffset = endOffset, Keyword = keyword, Position = position, Positionlength = positionlength, StartOffset = startOffset, Termfrequency = termfrequency, Token = token, Type = type, Attributes = additionalProperties };
		}

		public override void Write(Utf8JsonWriter writer, ExplainAnalyzeToken value, JsonSerializerOptions options)
		{
			throw new NotImplementedException("'ExplainAnalyzeToken' is a readonly type, used only on responses and does not support being written to JSON.");
		}
	}

	[JsonConverter(typeof(ExplainAnalyzeTokenConverter))]
	public sealed partial class ExplainAnalyzeToken
	{
		public Dictionary<string, object> Attributes { get; init; }

		public string Bytes { get; init; }

		public long EndOffset { get; init; }

		public bool? Keyword { get; init; }

		public long Position { get; init; }

		public long Positionlength { get; init; }

		public long StartOffset { get; init; }

		public long Termfrequency { get; init; }

		public string Token { get; init; }

		public string Type { get; init; }
	}
}